package com.chixing.day14_map.homework;

import java.util.*;


public class Product {
     private String brand;
     private String name;
     private double cost;

     public Product(String brand, String name,double cost){
         this.brand = brand;
         this.name = name;
         this.cost = cost;
     }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public static void main(String[] args) {

        List<Product> list = new ArrayList<>();
        Product p1 = new Product("宝洁","洗手粉",18.5);
        Product p2 = new Product("联合利华","肥皂",4.5);
        Product p3 = new Product("宝洁","牙膏",32.5);
        Product p4 = new Product("宝洁","毛巾",14.5);
        Product p5 = new Product("洁利","洗面奶",26.0);
        Product p6 = new Product("好迪","洗发水",27.5);
        Product p7 = new Product("多芬","沐浴露",38.5);
        Product p8 = new Product("宝洁","洗洁精",3.4);

        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        list.add(p5);
        list.add(p6);
        list.add(p7);
        list.add(p8);


        double a1 = 0;
        double a2 = 0;
        double a3 = 0;
        double a4 = 0;
        double a5 = 0;

        list.sort(Comparator.comparing(Product::getCost).reversed());
        for (Product ele : list){
            System.out.println(ele);
        }
        Iterator<Product> iterator = list.iterator();
        while (iterator.hasNext()){
            Product product = iterator.next();
            if (product.getBrand().equals("宝洁"))
                a1 += product.getCost();
            if (product.getBrand().equals("联合利华"))
                a2 += product.getCost();
            if (product.getBrand().equals("洁利"))
                a3 += product.getCost();
            if (product.getBrand().equals("好迪"))
                a4 += product.getCost();
            if (product.getBrand().equals("多芬"))
                a5 += product.getCost();


         }


        System.out.println("\"宝洁\"-"+a1);
        System.out.println("\"联合利华\"-"+a2);
        System.out.println("\"洁利\"-"+a3);
        System.out.println("\"好迪\"-"+a4);
        System.out.println("\"多芬\"-"+a5);







    }
}
